//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Input;
using OpenLS.Spreadsheet.UI.Internals;
using OpenLS.Spreadsheet.UI.Internals.Resources;

namespace OpenLS.Spreadsheet.UI
{
    public class ClipboardCommands
    {
        private static readonly RoutedUICommand[] _internalCommands = new RoutedUICommand[(int) CommandId.Last];


        public static RoutedUICommand PasteSpecial
        {
            get { return EnsureCommand(CommandId.PasteSpecial, "PasteSpecial"); }
        }


        public static RoutedCommand PasteValues
        {
            get { return EnsureCommand(CommandId.PasteValues, "PasteValues"); }
        }

        public static RoutedCommand FormatPainter
        {
            get { return EnsureCommand(CommandId.FormatPainter); }
        }

        public static RoutedCommand PasteFormulas
        {
            get { return EnsureCommand(CommandId.PasteFormulas); }
        }

        public static RoutedUICommand PasteTranspose
        {
            get { return EnsureCommand(CommandId.PasteTranspose); }
        }

        public static RoutedCommand PasteNoBorders
        {
            get { return EnsureCommand(CommandId.PasteNoBorders, "pasteNoBorder"); }
        }

        public static RoutedCommand PasteAsPicture
        {
            get { return EnsureCommand(CommandId.PasteAsPicture); }
        }

        private static RoutedUICommand EnsureCommand(CommandId commandId)
        {
            return EnsureCommand(commandId, commandId.ToString());
        }

        private static RoutedUICommand EnsureCommand(CommandId idCommand, string propertyName)
        {
            lock (_internalCommands.SyncRoot)
            {
                if (_internalCommands[(int) idCommand] == null)
                {
                    string text = GetText(idCommand);
                    if (text == null)
                        text = "!!Missing" + idCommand;
                    RoutedUICommand newCommand = new RoutedUICommand(text, propertyName, typeof (ClipboardCommands));
                    _internalCommands[(int) idCommand] = newCommand;
                }
            }
            return _internalCommands[(int) idCommand];
        }

        private static string GetText(CommandId idCommand)
        {
            switch (idCommand)
            {
                case CommandId.PasteValues:
                    return UIStringTable.PasteValues;
                case CommandId.PasteSpecial:
                    return UIStringTable.PasteSpecial;
                case CommandId.PasteAsPicture:
                    return UIStringTable.PasteSpecial;
                case CommandId.PasteFormulas:
                    return UIStringTable.PasteFormulas;
                case CommandId.FormatPainter:
                    return UIStringTable.FormatPainter;
                case CommandId.PasteNoBorders:
                    return UIStringTable.PasteNoBorder;
                case CommandId.PasteTranspose:
                    return UIStringTable.PasteTranspose;
                default:
                    throw new NotImplementedException();
            }
        }

        #region Nested type: CommandId

        private enum CommandId
        {
            PasteSpecial,
            PasteValues,
            PasteAsPicture,
            PasteNoBorders,
            PasteTranspose,
            PasteFormulas,
            FormatPainter,
            Last
        }

        #endregion
    }
}